/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-03-28 14:26:50
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-05-10 10:05:27
 * @FilePath: \code\cwp-front\pc-collaboration\src\handles\handle-list\summary\modules\custom\index.js
 * @Description: 自定义按钮
 */
import { updateFlow } from './helper';
//提交
import submit from '../continue-submit';
//暂存待办
import { comment } from '../comment';
//回退
import { returnFunction } from '../return';
//终止、撤销
import { chooseAttitude } from '../return/helper';
//移交
import { transfer } from '../transfer';

/**
 * @description: 自定义按钮操作。配置方式：
 * 单位管理员登录后台。协同BPM平台-流程基础设置-节点动作-新建
 * @param {String}attitude 封装态度
 * @param {String}submitAction 封装提交操作
 * @return {*}
 */
function customHandle(btn) {
    const { submitAction } = btn;
    console.log(submitAction);

    //如果有提交操作，就直接把态度和流程操作加进参数就行了。（不用展示页面交互）
    if (submitAction) {
        //有封装提交操作，就可能有态度
        //提交操作：提交、暂存待办、撤销、回退、终止、移交
        // continueSubmit: 提交
        // Comment: 暂存待办
        // Cancel: 撤销
        // Return: 回退
        // Terminate: 终止
        // Transfer: 移交
        switch (submitAction) {
            //提交
            case 'continueSubmit':
                submit.call(this, btn);
                break;
            //暂存待办
            case 'comment':
                comment.call(this, btn);
                break;
            //回退、指定回退
            case 'return':
            case 'specifiesReturn':
                returnFunction.call(this, btn);
                break;
            //终止、撤销
            case 'terminate':
            case 'cancel':
                chooseAttitude.call(this, btn);
                break;
            //移交
            case 'transfer':
                transfer.call(this, btn);
        }
    } else {
        //封装的流程操作。调用之后页面显示交互，并且如果确定之后就添加参数
        updateFlow.call(this, btn);
    }
}

export default function (btn) {
    return new Promise((resolve) => {
        customHandle.call(this, btn);
        resolve();
    });
}
